<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="author" content="Yb">
    <title>轮播图</title>
    <script src="../js/jquery-3.1.1.js"></script>
    <style>
        *{
            box-sizing: border-box;
        }
        ul,li,p{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        
        #box{
            font-family: 'Microsoft YaHei';
            font-size: 12px;
            width: 595px;
            height: 200px;
            margin: 0 auto;
            border: 1px solid#ccc;
            overflow: hidden;
            position: relative;
        }
        #box .nav-bar{
            width: 100%;
            height: 34px;
            background-image: url(img/btn_cartoon.gif);
            line-height: 20px;
            padding: 7px 12px;
            display: flex;
            justify-content: space-between;
        }
        #box .nav-bar .head{
            overflow: hidden;
        }
        #box .nav-bar .head>*{
            float: left;
        }
        #box .name{
            height: 20px;
            width: 80px;
            background-image: url(img/btn_cartoon.gif);
            background-position: -11px -108px;
        }
        #box .point{
            height: 20px;
            width: 60px;
            display: flex;
            justify-content: space-around;
            align-content: center;
            line-height: 20px;
        }
        #box .point li{
            width: 10px;
            height: 20px;
            background-image: url(img/btn_cartoon.gif);
            background-position: 0 211px;
        }
        #box .btn{
            width: 60px;
            height: 20px;
            margin-left: 5px;
            background-image: url(img/btn_cartoon.gif);
            background-position: 0 123px;
        }
        #box .btn span{
            display: block;
            width: 30px;
            height: 20px;
            float: left;
            cursor: pointer;
        }

        a{
            text-decoration: none;
            color: dodgerblue;
        }
        a:hover{
            text-decoration: underline;
            color: orangered;
        }
        
        #box .main{
            width: 2410px;
            overflow: hidden;
            position: absolute;
            top: 34px;
            left: 0;
        }
        #box .main>li{
            width: 585px;
            margin: 8px;
            float: left;
        }

        #box .main .content{
            width: 100%;
            overflow: hidden;
        }
        #box .main .content>li{
            width: 128px;
            margin: 8px;
            float: left;
        }
        #box .main .content img{
            margin-bottom: 5px;
        }

        #box .point li.active{
            background-position-y: -214px;
        }
    </style>
</head>
<body>
    <div id="box">
        <div class="nav-bar">
            <div class="head">
                <div class="name"></div>
                <ul class="point">
                    <li class="active"></li>
                    <li></li>
                    <li></li>
                    <li></li>
                </ul>
                <div class="btn">
                    <span class="prev"></span>
                    <span class="next"></span>
                </div>
            </div>
            <div class="head">
                <a href="javascript:;"><em>更多&gt;&gt;</em></a>
            </div>
        </div>
        <ul class="main">
            <li>
                <ul class="content">
                    <li>
                        <a href=""><img src="img/01.jpg" alt=""><span>海贼王</span></a>
                        <p>播放：28,276</p>
                    </li>
                    <li>
                        <a href=""><img src="img/01.jpg" alt=""><span>海贼王</span></a>
                        <p>播放：28,276</p>
                    </li>
                    <li>
                        <a href=""><img src="img/01.jpg" alt=""><span>海贼王</span></a>
                        <p>播放：28,276</p>
                    </li>
                    <li>
                        <a href=""><img src="img/01.jpg" alt=""><span>海贼王</span></a>
                        <p>播放：28,276</p>
                    </li>
                </ul>
            </li>
            <li>
                <ul class="content">
                    <li>
                        <a href=""><img src="img/02.jpg" alt=""><span>哆啦A梦</span></a>
                        <p>播放：28,276</p>
                    </li>
                    <li>
                        <a href=""><img src="img/02.jpg" alt=""><span>哆啦A梦</span></a>
                        <p>播放：28,276</p>
                    </li>
                    <li>
                        <a href=""><img src="img/02.jpg" alt=""><span>哆啦A梦</span></a>
                        <p>播放：28,276</p>
                    </li>
                    <li>
                        <a href=""><img src="img/02.jpg" alt=""><span>哆啦A梦</span></a>
                        <p>播放：28,276</p>
                    </li>
                </ul>
            </li>
            <li>
                <ul class="content">
                    <li>
                        <a href=""><img src="img/03.jpg" alt=""><span>火影忍者</span></a>
                        <p>播放：28,276</p>
                    </li>
                    <li>
                        <a href=""><img src="img/03.jpg" alt=""><span>火影忍者</span></a>
                        <p>播放：28,276</p>
                    </li>
                    <li>
                        <a href=""><img src="img/03.jpg" alt=""><span>火影忍者</span></a>
                        <p>播放：28,276</p>
                    </li>
                    <li>
                        <a href=""><img src="img/03.jpg" alt=""><span>火影忍者</span></a>
                        <p>播放：28,276</p>
                    </li>
                </ul>
            </li>
            <li>
                <ul class="content">
                    <li>
                        <a href=""><img src="img/04.jpg" alt=""><span>七龙珠</span></a>
                        <p>播放：28,276</p>
                    </li>
                    <li>
                        <a href=""><img src="img/04.jpg" alt=""><span>七龙珠</span></a>
                        <p>播放：28,276</p>
                    </li>
                    <li>
                        <a href=""><img src="img/04.jpg" alt=""><span>七龙珠</span></a>
                        <p>播放：28,276</p>
                    </li>
                    <li>
                        <a href=""><img src="img/04.jpg" alt=""><span>七龙珠</span></a>
                        <p>播放：28,276</p>
                    </li>
                </ul>
            </li>
        </ul>
    </div>
</body>
</html>

<script>
$(function(){
    var index = 0;
    // 上一页
    function nextPage(){
        index = index==$('.main>li').length-1 ? 0 : index+1;
        showPage();
    }
    // 下一页
    function prevPage(){
        index = index==0 ? $('.main>li').length-1 : index-1;
        showPage();
    }

    // 切换页面和指示灯
    function showPage(){
        // outerWidth(true)获取元素宽度(包括内边距、边框和外边距)
        var poLeft = -(($('.main li').outerWidth(true)) * index);
        $('.main').stop().animate({
            left:poLeft
        },600);
        $('.point li').eq(index).addClass('active')
                    .siblings().removeClass('active');
    }


    // 点击切换
    $('.btn .prev').click(function(){
        prevPage();
    })
    $('.btn .next').click(function(){
        nextPage();
    })

})
</script>